﻿namespace ClassyBlog.Web
{
    using System;

    using DomainObjects;
    using Infrastructure;

    public static class ArticleViewHelper
    {
        public static void SetViewPropertiesFrom<TArticle>(
            this IViewBagContainer instance, TArticle article)
            where TArticle : class, IHasTitle, IHasMetadata, IHasAuthor
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            if (article == null)
            {
                throw new ArgumentNullException("instance");
            }

            instance.ViewBag.Title = article.Title;

            if (!string.IsNullOrWhiteSpace(article.MetaKeywords))
            {
                instance.ViewBag.MetaKeywords = article.MetaKeywords;
            }

            if (!string.IsNullOrWhiteSpace(article.MetaDescription))
            {
                instance.ViewBag.MetaDescription = article.MetaDescription;
            }

            if (!string.IsNullOrWhiteSpace(article.Author))
            {
                instance.ViewBag.Author = article.Author;
            }
        }
    }
}